<?php
/**
 * 会话
 */

namespace diablo\lib;


class Conversation
{
    //设置session
    public function setSession($name, $value)
    {
        if (!$_SESSION) {
            session_start();
        }
        $_SESSION[$name] = $value;
    }

    //获取session
    public function getSession($name)
    {
        if (!$_SESSION) {
            session_start();
        }
        return $_SESSION[$name];
    }

    //销毁session
    public function removeSession($name = null)
    {
        if ($name) {
            unset($_SESSION['user']);
        } else {
            session_destroy();
        }
    }

    //设置cookie
    public function setCookie($name, $value, $time = null)
    {
        $value = serialize($value);//序列化数组
        setcookie($name, $value, $time, '/');
    }

    //取出cookie
    public function getCookie($name)
    {
        return unserialize($_COOKIE[$name]);
    }

    //销毁Cookie
    public function removeCookie($name)
    {
        setcookie($name, '', time() - 1, '/');
    }
}